import { Api } from "../../utils/api"
import http from "../../utils/http"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    buttonLoadingVisible: false
  },

  cancelClick() {
    wx.navigateBack({
      delta: 2,
    })
  },
  getUserProfile(e) {
    const _this = this
    wx.login({
      success: r => {
        const data = {
          code: r.code,
        }
        _this.setData({buttonLoadingVisible: true})
        http.postRequest(Api.login, data, (result) => {
          _this.setData({buttonLoadingVisible: false})
          if (result.success) {
            wx.setStorageSync('token', result.data.token);
            wx.setStorageSync('companyId', result.data.companyId);
            wx.setStorageSync('userInfo', result.data.data);
            wx.navigateBack({delta: 1})
          } else {
            wx.showToast({title: '授权登录失败', duration: 1000, icon: "none"});
          }
        })
      }
    })
  }
})
